<template>
  <div class="container">
    <el-dialog
      title="题目预览"
      :visible="showDialog"
      @close="close"
      width="900px"
    >
      <!-- 表单组件  el-form   label-width设置label的宽度   -->
      <!-- 匿名插槽 -->
      <el-row>
        <el-col :span="6" style="margin-bottom: 10px">
          【题型】：{{ answerList.questionType }}
        </el-col>
        <el-col :span="6" style="margin-bottom: 10px">
          【编号】：{{ answerList.id }}
        </el-col>
        <el-col :span="6" style="margin-bottom: 10px">
          【难度】：{{ answerList.difficulty }}
        </el-col>
        <el-col :span="6" style="margin-bottom: 10px">
          【标签】：{{ answerList.tags }}
        </el-col>
        <el-col :span="6" style="margin-bottom: 10px">
          【学科】：{{ answerList.subjectName }}
        </el-col>
        <el-col :span="6" style="margin-bottom: 10px">
          【目录】：{{ answerList.directoryName }}
        </el-col>
        <el-col :span="6" style="margin-bottom: 10px">
          【方向】：{{ answerList.direction }}
        </el-col>
      </el-row>
      <hr />
      <!-- 单选题类型答案 -->
      <div v-if="answerList.questionType === '1'">
        【题干】：
        <div v-html="answerList.question" style="color: blue"></div>
        <div style="padding-bottom: 5px">
          单选题 选项：（以下选中的选项为正确答案）
        </div>
        <div
          style="padding: 8px 0px"
          v-for="(item, index) in answerList.options"
          :key="index"
        >
          <el-radio :value="item.isRight === 1 ? index : ''" :label="index">{{
            item.title
          }}</el-radio>
        </div>
      </div>
      <!-- 多选题类型答案 -->
      <div v-else-if="answerList.questionType === '2'">
        【题干】：
        <div v-html="answerList.question" style="color: blue"></div>
        <div style="padding-bottom: 5px">
          多选题 选项：（以下选中的选项为正确答案）
        </div>
        <div
          style="padding: 8px 0px"
          v-for="(item, index) in answerList.options"
          :key="index"
        >
          <el-checkbox :value="item.isRight === 1 ? true : false">{{
            item.title
          }}</el-checkbox>
        </div>
      </div>
      <!-- 简答题类型答案 -->
      <!-- 多选题类型答案 -->
      <div v-else-if="answerList.questionType === '3'">
        【题干】：
        <div v-html="answerList.question" style="color: blue"></div>
      </div>
      <hr />
      <!-- 参考答案 -->
      <div>
        【参考答案】：
        <el-button type="danger" size="small" @click="showVideo">
          视频答案预览</el-button
        >
        <div style="width: 400px; height: 300px" v-if="show">
          <video
            controls
            style="width: 100%; height: 100%"
            src=" answerList.videoURL"
            ref="video"
          ></video>
        </div>
      </div>
      <hr />
      <!-- 答案解析 -->
      【答案解析】：
      <div style="display: inline-block" v-html="answerList.answer"></div>
      <hr />
      <!-- 题目备注 -->
      【题目备注】：
      <div style="display: inline-block" v-html="answerList.remarks"></div>
      <!-- el-dialog有专门放置底部操作栏的 插槽  具名插槽 -->
      <el-row slot="footer" type="flex" justify="end">
        <!-- 列被分为24 -->
        <el-col :span="6">
          <el-button type="primary" size="medium" @click="close"
            >关闭</el-button
          >
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { questionType, difficulty } from '@/api/hmmm/constants.js'
export default {
  name: 'QuestionPreview',
  data () {
    return {
      show: false
    }
  },
  props: {
    showDialog: {
      type: Boolean,
      default: false // 传true
    },
    answerList: {
      type: Object,
      required: true
      // 传详情
    }
  },
  methods: {
    questionType (value) {
      const obj = questionType.find((item) => +item.value === +value)
      return obj ? obj.label : '未知'
    },
    difficulty (value) {
      const obj = difficulty.find((item) => +item.value === +value)
      return obj ? obj.label : '未知'
    },
    close () {
      this.$emit('update:showDialog', false)
      this.show = false
    },
    showVideo () {
      if (this.answerList.videoURL) {
        this.show = true
      } else {
        this.$message.success('此题目无视频解析')
      }
    }
  },
  created () {
    this.answerList.questionType = this.questionType(
      this.answerList.questionType
    )
    this.answerList.difficulty = this.difficulty(this.answerList.difficulty)
  }
}
</script>
